<template>
    <inputSelect  v-model="fid" ref="warearea"
                  :f7Param="f7Param" 
                  :f7Disable="disabled"
                  :title="title"
                  :loadShow="loadShow"
                  :placeholder="placeholder"
                  :onF7DaTaSelected="onF7DaTaSelected"
                  v-on:onF7DaTaSelected="onF7DaTaSelected"
                  >
    </inputSelect>
</template>
<script>
export default {
    name: 'tmdm_warearea',
    props:{
        disabled : {type : Boolean},
        value : { type: [Number,String] },
        loadShow : [String],
        filter : {type : Array,default:null },
        placeholder:{type : String}
    },
    data(){
        return{
            title : '库区列表',
            fid : null,
            f7Param :{
                    selectId:'fid',
                    selectUrl:'/tie-mdm/warearea/queryListPageForF7',
                    selectTreeField:['fwarehouseid'],
                    selectTreeUrl:'/tie-mdm/warehouse/queryHouseTreeForF7',
                    selectShow:{spt:'',field:['fname']},
                    column:[
                            {lable:'库区编码',prop:'fnumber',isFilter:true,filterField:'fnumber'},
                            {lable:'库区名称',prop:'fname',isFilter:true,filterField:'fname'}
                    ],
                    defaultFilter:[{field:'fstatus',value:"USED"}],
                    defaultTreeFilter:[{field:'fstatus',value:"USED"}]
            },
        }
    },
    created(){
        if(this.filter != null){
            let realFilter = [];
            realFilter = this.f7Param.defaultFilter.concat(this.filter)
            this.f7Param.defaultFilter = realFilter; 
            let realTreeFilter = [];
            realTreeFilter = this.f7Param.defaultTreeFilter.concat(this.filter)
            this.f7Param.defaultTreeFilter = realTreeFilter; 
        }
    },
    methods:{
       onF7DaTaSelected(row){
            if(this.$tie.isEmpty(row)){
                this.$emit('input',null)
            }else{
                this.$emit('input',row[this.f7Param.selectId])
            }
            this.$emit('change',row)
       },
       cleanF7(isChange){
           this.$refs.warearea.cleanF7(isChange) 
       },
       defaultSelect(data){
           this.$refs.warearea.defaultSelect(data) 
           this.$emit('input',data[this.f7Param.selectId])

       },
       refresh(filters){
           let realFilter = [];
           let realTreeFilter = [];
           if(this.filter!=null){
               realFilter = this.f7Param.defaultFilter.concat(this.filter)
               realTreeFilter = this.f7Param.defaultTreeFilter.concat(this.filter)
           }
           if(filters != null){
               realFilter = realFilter.concat(filters)
               realTreeFilter = realTreeFilter.concat([{field:'fid',value:filters[0].value}])
           }
           this.f7Param.defaultFilter = realFilter; 
           this.f7Param.defaultTreeFilter = realTreeFilter;
           this.$refs.warearea.refresh() 
       }
    }
}
</script>